package com.sugar.real.estate.module.business.controller.app.readyhouse;

import com.sugar.real.estate.framework.common.pojo.CommonResult;
import com.sugar.real.estate.framework.common.pojo.PageParam;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.real.estate.module.business.controller.app.readyhouse.vo.AppReadyHouseDetailRespVO;
import com.sugar.real.estate.module.business.controller.app.readyhouse.vo.AppReadyHousePageReqVO;
import com.sugar.real.estate.module.business.controller.app.readyhouse.vo.AppReadyHouseSimpleRespVO;
import com.sugar.real.estate.module.business.service.readyhouse.ReadyHouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.util.List;

import static com.sugar.real.estate.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 现房")
@RestController
@RequestMapping("/biz/ready-house")
@Validated
public class AppReadyHouseController {

    @Resource
    private ReadyHouseService readyHouseService;

    @GetMapping("/get")
    @Operation(summary = "获得现房")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<AppReadyHouseDetailRespVO> getReadyHouse(@RequestParam("id") Long id) {
        return success(readyHouseService.appGetReadyHouse(id, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/page")
    @Operation(summary = "获得现房分页")
    @PermitAll
    public CommonResult<PageResult<AppReadyHouseSimpleRespVO>> getReadyHousePage(@Valid AppReadyHousePageReqVO reqVO) {
        return success(readyHouseService.appGetReadyHousePage(reqVO));
    }

    @GetMapping("/map")
    @Operation(summary = "地图查询现房")
    @PermitAll
    public CommonResult<List<AppReadyHouseSimpleRespVO>> getReadyHouseListByMap(AppReadyHousePageReqVO reqVO) {
        reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        return success(readyHouseService.getReadyHouseListByMap(reqVO));
    }
}